﻿using UnityEngine;
using System.Collections;

public class EnemyRoomController : MonoBehaviour 
{
	public int spawnedEnemies;
	public GameObject elevator;
	public GameObject door;

	public bool roomCleared;
	private float elevatorSpeed;
	private DoorController doorController;

	void Start()
	{
		elevatorSpeed = 0.09f;
		doorController = door.GetComponent<DoorController> ();
	}

	public void IncreaseEnemyCount()
	{
		++spawnedEnemies;
		doorController.targetCount = spawnedEnemies;
	}

	public void DecreaseEnemyCount()
	{
		--spawnedEnemies;
		doorController.targetCount = spawnedEnemies;
		if(spawnedEnemies <= 0)
		{
			roomCleared = true;
			spawnedEnemies = 0;
		}

		if(roomCleared)
		{
			ActivateElevator();
		}
	}

	void ActivateElevator()
	{
		if(elevator)
		{
			PlatformVerticalMovement elevScript = elevator.GetComponent<PlatformVerticalMovement>();
			elevScript.speed = elevatorSpeed;
		}
	}
}
